package com.ashen.study.test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author hxl
 * @Classname NutritionFacts
 * @Description
 * @Date 2019/11/21 10:15
 */
public class NutritionFacts {

    private static Logger logger = LoggerFactory.getLogger(NutritionFacts.class);

    private int servingSize;
    private int servings;
    private int calories;
    private int fat;
    private int sodium;
    private int carbohydrate;


    public static class Builder {
        private int servingSize;
        private int servings;
        private int calories = 0;
        private int fat = 0;
        private int sodium = 0;
        private int carbohydrate = 0;

        public Builder(int servingSize, int servings) {
            this.servingSize = servingSize;
            this.servings = servings;
        }

        public Builder calories(int val) {
            calories = val;
            return this;
        }

        public Builder fat(int val) {
            fat = val;
            return this;
        }

        public Builder sodium(int val) {
            sodium = val;
            return this;
        }

        public Builder carbohydrate(int val) {
            carbohydrate = val;
            return this;
        }

        public NutritionFacts build() {
            return new NutritionFacts(this);
        }
    }

    private NutritionFacts(Builder builder) {
        servingSize = builder.servingSize;
        servings = builder.servings;
        calories = builder.calories;
        fat = builder.fat;
        sodium = builder.sodium;
        carbohydrate = builder.carbohydrate;
    }


    public static void main(String[] args) {
        NutritionFacts cocaCola = new Builder(240, 8).calories(100).fat(599).build();
        logger.info(String.valueOf(cocaCola));
    }
}
